package com.project.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * 上下文创建、销毁监听器
 */
public class ContextLis implements ServletContextListener {
    //上下文对象创建时触发
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("上下文对象创建");
        //得到上下文对象
        ServletContext context = sce.getServletContext();
        //绑定在线人数共享数据
        context.setAttribute("onLine",0);
    }

    //上下文对象销毁时触发
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("上下文对象销毁");
    }
}
